<?php
if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Show extends CI_Controller
{
    
    function index()
    {
        $this->load->helper('url');
        echo 'show controller<br />mylist is '.url_mine(anchor('show/select' ,'this' ,'title="chick me!" style="color:#5f5f5f;"')).'!<br />';
        $this->load->library('calendar');
        echo $this->calendar->generate();        
    }
    
    function select()
    {
        $this->load->model('news');
        $this->load->helper(array('url','form'));
        $this->load->helper('form');
        $this->load->library('form_validation');
        $this->form_validation->set_message('min_length', '%s最少需要%d个字');
        $this->form_validation->set_message('max_length', '%s最多%d个字');
        $this->form_validation->set_rules('title', '标题', 'trim|required|min_length[5]|max_length[80]');
        $this->form_validation->set_rules('content', '内容', 'trim|required|min_length[10]|max_length[500]|htmlspecialchars');
        if($this->form_validation->run() == FALSE)
        {
            echo 'error_post,'.url_mine(anchor('show/select' ,'repeat' ,'title="chick me!" style="color:#5f5f5f;"'));
        }
        else
        {
            $title = $this->input->post('title');
            $content = $this->input->post('content');
            $insert = array(
                            'title' => $title,
                            'content' => $content,
                            'type' => 0,
                            'authorid' => 1,
                            'display' => 1,
                            'dateline' => time(),
                            'lastupdate' => time(),
                            );
            if ($this->news->insert($insert)) $this->db->cache_delete('/show' ,'select');
        }
        $data['record'] = $this->news->getAll();
        $this->load->view('showlist' , $data);
    }
    
    function images()
    {
        // 创建一个 200X200 的图像
        $img = imagecreatetruecolor(200, 200);
        // 分配颜色
        $white = imagecolorallocate($img, 255, 255, 255);
        imagefill($img ,0 ,0 ,$white);
        $black = imagecolorallocate($img, 0, 0, 0);
        // 画一个黑色的圆
        imagearc($img, 100, 100, 50, 150, 0, 360, $black);
        imagearc($img, 100, 100, 150, 50, 0, 360, $black);
        $img = imagerotate($img ,45 ,$white);
        imagearc($img ,141 ,141 ,50 ,150 ,0 ,360 ,$black);
        imagearc($img ,141 ,141 ,150 ,50 ,0 ,360 ,$black);
        $newimg = imagecreatetruecolor(151 ,151);
        imagecopy($newimg ,$img ,0 ,0 ,66 ,66 ,200 ,200);
        // 将图像输出到浏览器
        header("Content-type: image/png");
        imagepng($newimg);
        // 释放内存
        imagedestroy($img);
    }
    
    function cart()
    {
        $this->load->library('cart');
        $this->load->helper('form');
        $data = array(
                    'id' => 'music_2135',
                    'qty' => 1,
                    'name' => 'music_cd_taylor_swift_2',
                    'price' => 15,
                    'options' => array('author' => 'Taylor Swift' ,'copyright' => 2013)
                    );
        $this->cart->insert($data);
        //echo '<pre>'.var_export($this->cart->contents() ,true);
        $this->load->view('showcart');
    }
}

?>